/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package queenb.web.financial.controller;


import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFPrintSetup;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.CellRangeAddress;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.PrintSetup;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xwpf.usermodel.ParagraphAlignment;
import org.apache.poi.xwpf.usermodel.VerticalAlign;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;
import queenb.net.entitybean.M650;
import queenb.net.entitybean.N100;
import queenb.net.entitybean.N950;
import queenb.net.entitybean.T950;
import queenb.web.controller.QueenbController;
import queenb.web.crm.controller.V030controller;
import queenb.web.crm.store.CustomerStore;
import queenb.web.crm.store.V030Store;
import queenb.web.financial.inteface.FinancialInf;
import queenb.web.financial.store.FinancialStore;
import queenb.web.store.ContactStore;
import queenb.web.store.EmployeeStore;
import queenb.web.store.M650Store;
import queenb.web.util.ComboboxUtil;
import queenb.web.util.ContextUtil;
import queenb.web.util.ResourcesProvider;
import queenb.web.util.SessionName;
import queenb.web.util.SessionProvider;
import queenb.web.util.Util;

/**
 *
 * @author Nguyen Hung
 */
public class FinancialController extends QueenbController {

    private int ft950;
    private int pv050;
    private int pt950;
    private int fh075;
    private String hv076;
    private int ft000;
    private int tn951;
    private String tv952;
    private Date td953;
    private Date td954;
    private String tv955;
    private String tv956;
    private String tv957;
    private String tv958;
    private int tn959;
    private String tv960;
    private String tv961;
    private String tv962;
    private String tv963;
    private Date td964;
    private String tv965;
    private Date td966;
    private String tv967;
    private String tv968;
    private String tv969;
    private String tv970;
    private String tv971;
    private int fn100;// khach hàng lẻ
    private int fv500;
    private int fv650;
    private int ft900;
    private int fb050;
    private int fh000;
    private int fh200;
    private String td953st;
    private String td954st;
    private int pn100t;
    private int pt075;
    private FinancialInf t950Inf;
    private ComboboxUtil comboboxUtil;
    private List<T950> listT950;
    private List<T950> listT950forTour = new ArrayList<T950>();
    private List<T950> listT950CN;
    private List<T950> listT950CNL;
    List<N100> listN100CNKH;
    private FinancialStore t950Store;
    private String table;
    private int flag;
     private Workbook wb = new HSSFWorkbook();
    private String mycolor;
    private String tn951St;
    private String papeload;
    private int different = 0;
    private List<SelectItem> listCN = new ArrayList<SelectItem>();
    private int tip;
    private int FT950CN;// muc dich thu chi
    private String keysearch;
    private int typesearch = 0;// 
    private int idtype;//phan biet List khach hang va cong no
    private List<N100> listresultpersonal = new ArrayList<N100>();
    private int typecus;// phân biêt kach hang or nhan vien
    private Boolean flagcus;// phân biêt kach hang or nhan vien
    private String block = "none";// block// none
    private String none = "none";// block// none
    private String block1 = "none";// block// none
    private String none1 = "none";// block// none
    private String hoten;// block// none
    private String adddress;// block// none
    private String tv076;// lydo
    private String dd;
    private String mm;
     private SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
    private String yy;
    private int flagradio;// giam gia theo % or tien
    private double dbmoney;// gai tri khi giam
    private List<T950> listT950CNchild = new ArrayList<T950>();
    private String doanhsoStr;
    private String thuStr;
    private String tongnoStr;
    private String tongchiStr;

    public FinancialController() {
        comboboxUtil = new ComboboxUtil();

        t950Store = new FinancialStore();
        //   flag = Integer.parseInt(SessionProvider.getSessionMapValue("acti").toString());
        Object objectFn100 = getRequest().getParameter("id");
        if (objectFn100 != null) {
            fn100 = Integer.parseInt(objectFn100.toString());

        }
        Object objectChoose = getRequest().getParameter("pn100");
        if (objectChoose != null) {
            fn100 = Integer.parseInt(objectChoose.toString());
            setFlagcus(true);
            System.out.println(flagcus + "---AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA------------------" + fn100);
            if (fn100 != 0) {
                SessionProvider.setSessionMapValue(SessionName.PN100NEWKEY, fn100);
            }

        }
        Object objectpt950 = getRequest().getParameter("pt950");
        // Object objectpt950trigger = getRequest().getParameter("pt950");
        if (objectpt950 != null) {
            pt950 = Integer.parseInt(objectpt950.toString());

        }
        Object objectpttable = getRequest().getParameter("table");

        try {
            Object papeload1 = getRequest().getParameter("page");
            if (papeload1 != null) {

                papeload = papeload1.toString();
                setDifferent(1);
                System.out.println("*********aaaaaaaaaaaaaaaaaaaaaaaa***********" + papeload + different);
            }
        } catch (Exception e) {
        }
        if (objectpt950 != null && objectpttable != null) {
            pt950 = Integer.parseInt(objectpt950.toString());
            table = objectpttable.toString();
            System.out.println("********************" + table);
        }
        Object objAction = getRequest().getParameter("action");
        if (objAction != null) {
            if (objAction.equals("edit")) {
                Object objPt950 = getRequest().getParameter("pt950");
                if (objPt950 != null) {
                    pt950 = Integer.parseInt(objPt950.toString());
                    getListT950ByID(pt950);
                }
            } else if (objAction.equals("delete")) {
                Object objPt950 = getRequest().getParameter("pt950");
                if (objPt950 != null) {
                    pt950 = Integer.parseInt(objPt950.toString());
                }
            } else if (objAction.equals("newpage")) {
                if (SessionProvider.getSessionMapValue("PAGELOADTOUR") != null && SessionProvider.getSessionMapValue("IDPAGELOADTOUR") != null) {
                    SessionProvider.removeSessionMapValue("PAGELOADTOUR");
                    SessionProvider.removeSessionMapValue("IDPAGELOADTOUR");
                }
            } else if (objAction.equals("editCN")) {
                Object objPt950 = getRequest().getParameter("pt950");
                Object objectPN100 = getRequest().getParameter("pn100");
                if (objPt950 != null) {
                    pt950 = Integer.parseInt(objPt950.toString());
                    fn100 = Integer.parseInt(objectPN100.toString());
                    getListT950ByIDCN(pt950);
                }
            } else if (objAction.equals("document")) {
                tip = 1;
            } else if (objAction.equals("documentCN")) {
                tip = 0;
            } else if (objAction.equals("editCNL")) {
                Object objPt950 = getRequest().getParameter("pt950");
                Object objPage = getRequest().getParameter("page");
                if (objPt950 != null) {
                    papeload = objPage.toString();
                    pt950 = Integer.parseInt(objPt950.toString());
                    ft950 = pt950;
                    getListT950ByIDCNL(pt950);
                }
            } else if (objAction.equals("predebt")) {
//                if (SessionProvider.getSessionMapValue("FT950CN") != null) {
//                    SessionProvider.removeSessionMapValue("FT950CN");
//                }

                Object objPt950 = getRequest().getParameter("ft950");
                if (objPt950 != null) {
                    pt950 = Integer.parseInt(objPt950.toString());
                    System.out.println("-----------CN PTCHILD-------" + pt950);
                    // SessionProvider.setSessionMapValue("FT950CN", FT950CN);
                }
            } else if (objAction.equals("editCNKH")) {
                Object objectPN100 = getRequest().getParameter("pn100");
                if (objectPN100 != null) {
                    fn100 = Integer.parseInt(objectPN100.toString());
                    System.out.println("--------PN100---------" + fn100);
                }

            } else if (objAction.equals("editCNLitem")) {
                Object objPt950 = getRequest().getParameter("pt950");
                Object objectPN100 = getRequest().getParameter("pn100");
                if (objPt950 != null) {
                    pt950 = Integer.parseInt(objPt950.toString());
                    fn100 = Integer.parseInt(objectPN100.toString());
                    getListT950ByIDCNitem(pt950);
                }

            } else if (objAction.equals("addCNforTour")) {
                Object objectPage = getRequest().getParameter("page");
                Object objectfb0501 = getRequest().getParameter("fb050");
                if (objectfb0501 != null) {
                    fb050 = Integer.parseInt(objectfb0501.toString());
                }
                if (objectPage != null) {
                    papeload = objectPage.toString();
                }
                SessionProvider.setSessionMapValue("PAGELOADTOUR", papeload);
                SessionProvider.setSessionMapValue("IDPAGELOADTOUR", fb050);

            } else if (objAction.equals("addEmp")) {
                if (SessionProvider.getSessionMapValue(SessionName.KEYSEARCHNAME) != null) {
                    SessionProvider.removeSessionMapValue(SessionName.KEYSEARCHNAME);
                    System.out.println("----------REMOVE SS--------" + fn100);
                }
                if (SessionProvider.getSessionMapValue(SessionName.PN100NEWKEY) != null) {
                    SessionProvider.removeSessionMapValue(SessionName.PN100NEWKEY);
                    System.out.println("----------REMOVE SS--------" + fn100);
                }

            } else if (objAction.equals("getinfomationEmp")) {
                Object objectpt950o = getRequest().getParameter("pt950");
                if (objectpt950o != null) {
                    pt950 = Integer.parseInt(objectpt950o.toString());
                    SessionProvider.setSessionMapValue(SessionName.PT950NEWKEY, pt950);
                    getListT950ByID(pt950);
                }
            } else if (objAction.equals("getsaleTour")) {
                Object objectpt950o = getRequest().getParameter("pt950");
                if (objectpt950o != null) {
                    pt950 = Integer.parseInt(objectpt950o.toString());

                }
                Object objectpt950o1 = getRequest().getParameter("fn100");
                if (objectpt950o1 != null) {
                    fn100 = Integer.parseInt(objectpt950o1.toString());

                }
            } else if (objAction.equals("addchildPt950")) {
                Object objectpt950o = getRequest().getParameter("pt950");
                if (objectpt950o != null) {
                    pt950 = Integer.parseInt(objectpt950o.toString());

                }
                Object objectpt95f = getRequest().getParameter("ft950");
                if (objectpt95f != null) {
                    ft950 = Integer.parseInt(objectpt95f.toString());

                }
                Object objectpt950o1 = getRequest().getParameter("fn100");
                if (objectpt950o1 != null) {
                    fn100 = Integer.parseInt(objectpt950o1.toString());

                }
                Object objectpt950o12 = getRequest().getParameter("fv050");
                if (objectpt950o12 != null) {
                    pv050 = Integer.parseInt(objectpt950o12.toString());

                }
                Object objTV957 = getRequest().getParameter("tv957");
                if (objTV957 != null) {
                    tv957 = objTV957.toString();

                }

                System.out.println(tv957 + "--# TAHM SO----" + pt950 + fn100 + pv050);
            } else if (objAction.equals("editchildPt950")) {
                Object objectpt950o = getRequest().getParameter("pt950");
                if (objectpt950o != null) {
                    pt950 = Integer.parseInt(objectpt950o.toString());

                }
                Object objectpt950o1 = getRequest().getParameter("fn100");
                if (objectpt950o1 != null) {
                    fn100 = Integer.parseInt(objectpt950o1.toString());

                }
                Object objectpt950o12 = getRequest().getParameter("fv050");
                if (objectpt950o12 != null) {
                    pv050 = Integer.parseInt(objectpt950o12.toString());

                }
                List<T950> listT950obj = t950Store.listT950CNforTournew(getLogin().getModule(), getLogin().getCompanyNo(), 0, ft000, 0, pv050, pt950, 0, 0, 300, 0, 0, getLogin().getUserName());

                System.out.println(listT950obj.size() + "--THAM SO KHI EDIT----" + pt950 + fn100 + pv050);
                if (listT950obj != null) {
                    tv952 = listT950obj.get(0).getTv952();
                    ft000 = listT950obj.get(0).getFt000();
                    tv952 = listT950obj.get(0).getTv952();
                    pt075 = listT950obj.get(0).getFt075();
                    pn100t = listT950obj.get(0).getFn100t();
                    pv050 = listT950obj.get(0).getFv050();
                    this.tn951 = listT950obj.get(0).getTn951();
                    if (tn951 != 0) {
                        double tn951db = Util.convertStringToDouble(String.valueOf(tn951));
                        tn951St = Util.numberformater(tn951db, "##,###,###");
                    }

                    this.td953 = listT950obj.get(0).getTd953();
                    this.td954 = listT950obj.get(0).getTd954();
                    this.tv957 = listT950obj.get(0).getTv957();
                    this.tv958 = listT950obj.get(0).getTv958();
                    this.tv969 = listT950obj.get(0).getTv969();
                    this.tv970 = listT950obj.get(0).getTv970();
                    this.tv971 = listT950obj.get(0).getTv971();
                    System.out.println("----VAO DAY----" + tv952);
                }
            }

        }
        Object objectfb050 = getRequest().getParameter("fb050");
        if (objectfb050 != null) {
            try {
                fb050 = Integer.parseInt(objectfb050.toString());
            } catch (Exception e) {
                fb050 = 0;
            }
        }
    }

    public List<SelectItem> getListCombH075() {

        return comboboxUtil.getListCombH075();
    }

    public List<SelectItem> getListCombT100() {

        return comboboxUtil.getListCombT100();
    }

    public List<SelectItem> getListCombT100CN() {

        return comboboxUtil.getListCombT100CN();
    }

    public List<SelectItem> getListCombB050() {

        return comboboxUtil.getListCombB050();
    }

    public List<SelectItem> getListCombV050() {

        return comboboxUtil.getListCombV050SGTCN();
    }

    public List<SelectItem> getListCombN100() {

        return comboboxUtil.getListCombN100F();
    }

    public List<SelectItem> getListCombN100Email() {

        return comboboxUtil.getListCombN100FF();
    }

    public List<SelectItem> getListCombT075() {

        return comboboxUtil.getlistCombT075();
    }

    public void reload() {
        System.out.println("-----------KEY của Công nợ --- OPITON" + keysearch + typesearch);
        SessionProvider.setSessionMapValue("KEY", keysearch);
        SessionProvider.setSessionMapValue("TYPE", typesearch);
        if (SessionProvider.getSessionMapValue("TYPE") != null) {
            idtype = Util.parseInt(SessionProvider.getSessionMapValue("TYPE"));
        }
    }

    public void deleteT950() {
        try {
            int row = 0;
            row = t950Store.deleteT950(pt950, tv968, getLogin().getUserName());
            sendRedirect("customer4tour.jsp");
//            if (row >= 0) {
//                showGlobalReport(true, getResourceString("datasavesuccessful"));
//                if (papeload.equals("debt.jsp")) {
//                    sendRedirect("debt.jsp");
//                } else {
//                    sendRedirect("financialAccount.jsp");
//                }
//            } else {
//                showGlobalReport(true, getResourceString("datasuccessfail"));
//                if (papeload.equals("debt.jsp")) {
//                    sendRedirect("debt.jsp");
//                } else {
//                    sendRedirect("financialAccount.jsp");
//                }
//            }
        } catch (Exception e) {
        }
    }

    public List<T950> getListT950CN() {
        getKapiMenu().setAdmin(false);
        getKapiMenu().setMainmenu1("m162");
        try {

            System.out.println("-----list----FN100----" + fn100);
            System.out.println("-----list--------" + getLogin().getModule() + "," + getLogin().getCompanyNo() + "," + this.getFh075() + "," + this.getFt000() + "," + this.getFb050() + "," + this.getFv500() + "," + this.getFt950() + "," + 0 + "," + 100 + "," + 0 + "," + 1 + "," + this.getLogin().getUserName());
            listT950CN = t950Store.listT950CN(getLogin().getModule(), getLogin().getCompanyNo(), this.getFh075(), this.getFt000(), this.getFb050(), this.getFv500(), this.getFt950(), 0, 100, 0, 1, this.getLogin().getUserName());
            return listT950CN;
        } catch (Exception ex) {
            return null;
        }
    }

    public List<T950> getListT950CNnew() {
        try {
            V030controller v030controller = new V030controller();
            System.out.println("-----list-----AAAAAAA---" + getLogin().getModule() + "," + getLogin().getCompanyNo() + "," + this.getFh075() + "," + this.getFt000() + "," + v030controller.getFV050() + "," + this.getFv500() + "," + this.getFt950() + "," + 0 + "," + 100 + "," + 0 + "," + 1 + "," + this.getLogin().getUserName());
            listT950CN = t950Store.listT950CN(getLogin().getModule(), getLogin().getCompanyNo(), this.getFh075(), this.getFt000(), v030controller.getFV050(), this.getFv500(), this.getFt950(), 0, 100, 0, 1, this.getLogin().getUserName());
            return listT950CN;
        } catch (Exception ex) {
            return null;
        }
    }

    public List<T950> getListT950CNH() {
        try {

            if (SessionProvider.getSessionMapValue("PN100HD") != null) {
                fn100 = Util.parseInt(SessionProvider.getSessionMapValue("PN100HD"));
            }
            System.out.println("-----list--------" + getLogin().getModule() + "," + getLogin().getCompanyNo() + "," + this.getFh075() + "," + this.getFt000() + "," + this.fn100 + "," + this.getFv500() + "," + this.getFt950() + "," + 0 + "," + 100 + "," + 0 + "," + 1 + "," + this.getLogin().getUserName());
            listT950CN = t950Store.listT950CNH(getLogin().getModule(), getLogin().getCompanyNo(), this.getFh075(), this.getFt000(), fn100, this.getFv500(), this.getFt950(), 0, 100, 0, 1, this.getLogin().getUserName());
            return listT950CN;
        } catch (Exception ex) {
            return null;
        }
    }

    public List<N100> getListT950CNKH() {


        getKapiMenu().setAdmin(false);
        getKapiMenu().setMainmenu1("m162");
        try {
            if (SessionProvider.getSessionMapValue("KEY") != null) {
                String key = SessionProvider.getSessionMapValue("KEY").toString();
                idtype = Util.parseInt(SessionProvider.getSessionMapValue("TYPE"));
                if (idtype == 2) {
                    EmployeeStore employeeStore = new EmployeeStore();
                    listN100CNKH = employeeStore.listT950CNKH(getLogin().getModule(), getLogin().getCompanyNo(), key, getLogin().getUserName());
                    System.out.println("---------------SIZE------" + listN100CNKH.size());
                }
            }



            return listN100CNKH;
        } catch (Exception ex) {
            return null;
        }
    }

    public void getListT950ByIDCN(int pnT950) {
        try {
            List<T950> listT950CN1 = getListT950CN();
            if (listT950CN1 != null && listT950CN1.size() > 0) {
                for (int i = 0; i < listT950CN.size(); i++) {
                    if (listT950CN1.get(i).getPt950() == pnT950) {
                        ft000 = listT950CN1.get(i).getFt000();
                        tv952 = listT950CN1.get(i).getTv952();
                        pt075 = listT950CN1.get(i).getFt075();
                        pn100t = listT950CN1.get(i).getFn100t();
                        pv050 = listT950CN1.get(i).getFb050();
                        this.tn951 = listT950CN1.get(i).getTn951();
                        if (tn951 != 0) {
                            double tn951db = Util.convertStringToDouble(String.valueOf(tn951));
                            tn951St = Util.numberformater(tn951db, "##,###,###");
                        }

                        this.td953 = listT950CN1.get(i).getTd953();
                        this.td954 = listT950CN1.get(i).getTd954();
                        this.tv957 = listT950CN1.get(i).getTv957();
                        this.tv958 = listT950CN1.get(i).getTv958();
                        this.tv969 = listT950CN1.get(i).getTv969();
                        this.tv970 = listT950CN1.get(i).getTv970();
                        this.tv971 = listT950CN1.get(i).getTv971();
//                        this.td954st = listT950.get(i).getTd954st().toString();
                        System.out.println("--Fttttttttttttttttttttttttttt---aaaaaaaaaaaaaaaaaaa--------" + ft000 + tv952);
                        break;
                    }
                }
            }
        } catch (Exception ex) {
            System.out.println("Error. ERROR CODE: " + ex.getMessage());
        }
    }

    public void getListT950ByIDCNitem(int pnT950) {
        try {
            int id = 0;
            if (SessionProvider.getSessionMapValue("FT950CN") != null) {
                id = Util.parseInt(SessionProvider.getSessionMapValue("FT950CN"));
            }
            List<T950> listT950CN1 = t950Store.listT950CNAdd(getLogin().getModule(), getLogin().getCompanyNo(), id, this.getLogin().getUserName());
            if (listT950CN1 != null && listT950CN1.size() > 0) {
                for (int i = 0; i < listT950CN1.size(); i++) {
                    if (listT950CN1.get(i).getPt950() == pnT950) {
                        ft000 = listT950CN1.get(i).getFt000();
                        tv952 = listT950CN1.get(i).getTv952();
                        pt075 = listT950CN1.get(i).getFt075();
                        pn100t = listT950CN1.get(i).getFn100t();
                        pv050 = listT950CN1.get(i).getFb050();
                        this.tn951 = listT950CN1.get(i).getTn951();
                        if (tn951 != 0) {
                            double tn951db = Util.convertStringToDouble(String.valueOf(tn951));
                            tn951St = Util.numberformater(tn951db, "##,###,###");
                        }

                        this.td953 = listT950CN1.get(i).getTd953();
                        this.td954 = listT950CN1.get(i).getTd954();
                        this.tv957 = listT950CN1.get(i).getTv957();
                        this.tv958 = listT950CN1.get(i).getTv958();
                        this.tv969 = listT950CN1.get(i).getTv969();
                        this.tv970 = listT950CN1.get(i).getTv970();
                        this.tv971 = listT950CN1.get(i).getTv971();
//                        this.td954st = listT950.get(i).getTd954st().toString();
                        System.out.println("--Fttttttttttttttttttttttttttt---aaaaaaaaaaaaaaaaaaa--------" + ft000 + tv952);
                        break;
                    }
                }
            }
        } catch (Exception ex) {
            System.out.println("Error. ERROR CODE: " + ex.getMessage());
        }
    }

    // edit thanh toan
    public void getListT950ByIDCNL(int pnT950) {
        try {
            List<T950> listT950CN1 = getListT950CN();
            if (listT950CN1 != null && listT950CN1.size() > 0) {
                for (int i = 0; i < listT950CN.size(); i++) {
                    if (listT950CN1.get(i).getPt950() == pnT950) {
                        pv050 = listT950CN1.get(i).getFb050();
                        fn100 = listT950CN1.get(i).getFn100();
                        FT950CN = listT950CN1.get(i).getPt950();
                        tv971 = listT950CN1.get(i).getTv971();
                        System.out.println("--Fttttttttttttttttttttttttttt---" + pv050 + pn100t + tv971);
                        break;
                    }
                }
            }
        } catch (Exception ex) {
            System.out.println("Error. ERROR CODE: " + ex.getMessage());
        }
    }

    public List<T950> getListT950() {
        try {
            if (listT950 == null) {
                V030controller v030controller = new V030controller();
                System.out.println("---------------HAM PRINT WORD-----------------" + getLogin().getModule() + "," + getLogin().getCompanyNo() + "," + 0 + "," + ft000 + "," + 0 + "," + v030controller.getFV050() + "," + SessionProvider.getSessionMapValue(SessionName.PT950NEWKEY) + "," + 0 + "," + 0 + "," + 300 + "," + 0 + "," + 0 + "," + getLogin().getUserName());
                listT950 = t950Store.listT950CNforTournew(getLogin().getModule(), getLogin().getCompanyNo(), 0, ft000, 0, v030controller.getFV050(), Util.parseInt(SessionProvider.getSessionMapValue(SessionName.PT950NEWKEY)), 0, 0, 300, 0, 0, getLogin().getUserName());
                pt950 = listT950.get(0).getPt950();



            }

            return listT950;
        } catch (Exception ex) {
            return null;
        }

    }

    public List<T950> getListT950CNL() {
        try {
            if (listT950CNL == null) {
                System.out.println("--list 7950---CNL-------------" + getLogin().getModule() + "," + getLogin().getCompanyNo() + "," + this.FT950CN + "," + this.getLogin().getUserName());
                listT950CNL = t950Store.listT950CNAdd(getLogin().getModule(), getLogin().getCompanyNo(), this.FT950CN, this.getLogin().getUserName());
            }

            return listT950CNL;
        } catch (Exception ex) {
            return null;
        }

    }

    public void updateTn950() throws ParseException {
        try {
            int roweffect = 0;
            String dateStart = ContextUtil.getRequestParameter("leavedate1");
            if (!dateStart.equals("")) {
                td953 = Util.parseDate(dateStart, "dd/MM/yyyy");
            } else {
                td953 = null;
            }
            String dateEnd = ContextUtil.getRequestParameter("leavedate2");
            if (!dateEnd.equals("")) {
                td954 = Util.parseDate(dateEnd, "dd/MM/yyyy");
            } else {
                td954 = null;
            }

//        Date date953 = new Date();
//        Timestamp timertd953 = new Timestamp(td953.getTime());
//        Timestamp timertd954 = new Timestamp(td954.getTime());

            tn951 = Integer.parseInt(Util.connectString(tn951St, ",").toString().trim());
            //   if (FT950CN != 0) {
            if (SessionProvider.getSessionMapValue(SessionName.PN100NEWKEY) != null) {
                fn100 = Util.parseInt(SessionProvider.getSessionMapValue(SessionName.PN100NEWKEY));
            }
            System.out.println("---------------ABC---------" + pt950 + "," + fh075 + "," + ft000 + ","
                    + tn951 + "," + tv952 + "," + Util.toSQLDate(td953) + "," + Util.toSQLDate(td954) + "," + tv955 + "," + tv956 + "," + tv957 + "," + tv958 + "," + tn959 + "," + tv969 + "," + tv970 + "," + tv971 + "," + pv050 + ","
                    + fv650 + "," + pv050 + "," + fn100 + "," + pt075 + "," + getLogin().getId() + "," + getLogin().getModule() + ",FT" + ft950 + "," + getLogin().getUserName());
            roweffect = t950Inf.updateT950(pt950, fh075, ft000,
                    tn951, tv952, Util.toSQLDate(td953), Util.toSQLDate(td954), "A", tv956, SessionProvider.getSessionMapValue(SessionName.TOUR_CODE).toString(), tv958, tn959, tv969, tv970, SessionProvider.getSessionMapValue(SessionName.TOUR_NAME).toString(), pv050,
                    fv650, pv050, fn100, pt075, getLogin().getId(), getLogin().getModule(), ft950, getLogin().getUserName());
            if (roweffect != 0) {
                showGlobalReport(true, getResourceString("datasavesuccessful"));
                sendRedirect("customer4tour.jsp");
            } else {
                showGlobalReport(true, getResourceString("datasuccessfail"));
                sendRedirect("customer4tour.jsp");
            }
//            } else {
//                 if(SessionProvider.getSessionMapValue(SessionName.PN100NEWKEY)!=null){
//                    fn100 = Util.parseInt(SessionProvider.getSessionMapValue(SessionName.PN100NEWKEY));
//                }
//                roweffect = t950Inf.updateT950(this.getPt950(), this.getFh075(), this.getFt000(),
//                        this.getTn951(), this.getTv952(), Util.toSQLDate(this.td953), Util.toSQLDate(this.td954),
//                        this.getTv955(), this.getTv956(), this.getTv957(), this.getTv958(),
//                        this.getTn959(), this.getTv969(), this.getTv970(), this.getTv971(), this.getPv050(),
//                        this.getFv650(), this.getPv050(), this.fn100, this.pt075, getLogin().getId(), getLogin().getModule(), this.FT950CN, getLogin().getUserName());
//            }
//

//            System.out.println("-----TUNG-----" + pt075 + papeload + fb050);
//            if (roweffect >= 0) {
//                System.out.println("--------------TANG------" + SessionProvider.getSessionMapValue("PAGELOAD") + SessionProvider.getSessionMapValue("IDPAGELOAD"));
//                if (SessionProvider.getSessionMapValue("PAGELOADTOUR") != null && SessionProvider.getSessionMapValue("IDPAGELOADTOUR") != null) {
//                    if (SessionProvider.getSessionMapValue("TYPE") != null) {
//                        SessionProvider.removeSessionMapValue("TYPE");
//                    }
//                    System.out.println("--------VAO DAY KO-----------");
//                    showGlobalReport(true, getResourceString("datasavesuccessful"));
//                    sendRedirect("debt.jsp?fb050=" + Util.parseInt(SessionProvider.getSessionMapValue("IDPAGELOADTOUR")) + "&page=" + SessionProvider.getSessionMapValue("PAGELOADTOUR").toString());
//                } else {
//                    showGlobalReport(true, getResourceString("datasavesuccessful"));
//                    if (papeload.equals("debt.jsp")) {
//                        if (SessionProvider.getSessionMapValue("TYPE") != null) {
//                            SessionProvider.removeSessionMapValue("TYPE");
//                        }
//
//                        sendRedirectUrlTab("debt.jsp?pt950=" + pt950 + "&linkdebt=" + Util.convertMD5(getRequest().getRequestURI()));
//                    } else if (papeload.equals("debt1.jsp")) {
//                        if (SessionProvider.getSessionMapValue("TYPE") != null) {
//                            SessionProvider.removeSessionMapValue("TYPE");
//                        }
//
//                        sendRedirect("debt.jsp");
//                    } else if (papeload.equals("customer.jsp")) {
//                        if (SessionProvider.getSessionMapValue("TYPE") != null) {
//                            SessionProvider.removeSessionMapValue("TYPE");
//                        }
//
//                        sendRedirectURL(papeload, fn100, 8);
//                    } else {
//                        if (SessionProvider.getSessionMapValue("TYPE") != null) {
//                            SessionProvider.removeSessionMapValue("TYPE");
//                        }
//                        sendRedirect("financialAccount.jsp");
//                    }
//                }
//            } else {
//                showGlobalReport(true, getResourceString("datasuccessfail"));
//                if (papeload.equals("debt.jsp")) {
//                    if (SessionProvider.getSessionMapValue("TYPE") != null) {
//                        SessionProvider.removeSessionMapValue("TYPE");
//                    }
//                    sendRedirectUrlTab("debt.jsp?pt950=" + pt950 + "&linkdebt=" + Util.convertMD5(getRequest().getRequestURI()));
//                } else {
//                    if (SessionProvider.getSessionMapValue("TYPE") != null) {
//                        SessionProvider.removeSessionMapValue("TYPE");
//                    }
//                    sendRedirect("financialAccount.jsp");
//                }
//            }
        } catch (Exception e) {
            System.out.println("------------DDD--" + e.getMessage());
        }

    }

    public void getListT950ByID(int pnT950) {
        try {
            listT950 = getListT950();
            if (listT950 != null && listT950.size() > 0) {
                for (int i = 0; i < listT950.size(); i++) {
                    if (listT950.get(i).getPt950() == pnT950) {
                        this.pt950 = listT950.get(i).getPt950();
                        this.fh075 = listT950.get(i).getFh075();
                        this.hv076 = listT950.get(i).getHv076();
                        this.ft000 = listT950.get(i).getFt000();
                        this.tn951 = listT950.get(i).getTn951();
                        if (tn951 != 0) {
                            double tn951db = Util.convertStringToDouble(String.valueOf(tn951));
                            tn951St = Util.numberformater(tn951db, "##,###,###");
                        }
                        this.pt075 = listT950.get(i).getFt075();
                        this.pn100t = listT950.get(i).getFn100t();

                        this.tv952 = listT950.get(i).getTv952();
                        this.td953 = listT950.get(i).getTd953();
                        System.out.println("---------Ngay thang--" + td953);
                        if (td953 != null) {
                            dd = td953.toString().substring(8, 10);
                            mm = td953.toString().substring(5, 7);
                            yy = td953.toString().substring(0, 4);
                        }
                        System.out.println("---------Ngay thang--" + dd + mm + yy);
                        this.td954 = listT950.get(i).getTd954();
                        this.tv955 = listT950.get(i).getTv955();
                        this.tv956 = listT950.get(i).getTv956();
                        this.tv957 = listT950.get(i).getTv957();
                        this.tv958 = listT950.get(i).getTv958();
                        this.tn959 = listT950.get(i).getTn959();
                        this.tv960 = listT950.get(i).getTv960();
                        this.tv961 = listT950.get(i).getTv961();
                        this.tv962 = listT950.get(i).getTv962();
                        this.tv963 = listT950.get(i).getTv963();
                       // this.td964 = listT950.get(i).getTd964();
                        this.tv965 = listT950.get(i).getTv965();
                       // this.td966 = listT950.get(i).getTd966();
                        this.tv967 = listT950.get(i).getTv967();
                        this.tv968 = listT950.get(i).getTv968();
                        this.tv969 = listT950.get(i).getTv969();
                        this.tv970 = listT950.get(i).getTv970();
                        this.tv971 = listT950.get(i).getTv971();
                        this.pv050 = listT950.get(i).getFb050();
                        tv076 = listT950.get(i).getTv076();
                        this.fv500 = listT950.get(i).getFb050();
                        System.out.println("----- " + tv971);
                        this.fv500 = listT950.get(i).getFv500();
                        this.fv650 = listT950.get(i).getFv650();
                        this.ft900 = listT950.get(i).getFt900();
                        this.fb050 = listT950.get(i).getFb050();
                        hoten = listT950.get(i).getHoten();
                        System.out.println("---HHHHHHHHHHHHHHHH-- " + hoten);
                        adddress = listT950.get(i).getNv112();
                        this.td953st = listT950.get(i).getTd953st().toString();
                        this.td954st = listT950.get(i).getTd954st().toString();
                    }
                }
            }
        } catch (Exception ex) {
            System.out.println("Error. ERROR CODE: " + ex.getMessage());
        }
    }

    public List<M650> getListdocumentM650CN() {
        M650Store store = new M650Store();
        try {

            List<M650> listM650 = store.findM650(getLogin().getModule(), getLogin().getCompanyNo(), 0, null, 0, 0, 0, null, "T950CN", 0, 0, null, null, 0, 10000, 0, 0, getLogin().getUserName());
            System.out.println("--------------------------" + listM650.size());
            return listM650;
        } catch (Exception e) {
            return null;
        }
    }

    public void faultfinding() {
        System.out.println("AAAAAAAAAAAa*****************" + flag);
        int roweffect = 0;
        System.out.println("PTTTTTTTTTTTTTTTTTTTTT" + pt950 + table);
        roweffect = t950Store.ConfirmT950(pt950, getLogin().getUserName());

        if (roweffect >= 0) {
//            flag = roweffect;
//            System.out.println("*****************" + flag);
            showGlobalReport(true, getResourceString("datasavesuccessful"));
//            if (SessionProvider.getSessionMapValue("PAGELOADTOUR") != null && SessionProvider.getSessionMapValue("IDPAGELOADTOUR") != null) {
//
//                System.out.println("--------VAO DAY KO-----------");
//                sendRedirect("debt.jsp?fb050=" + Util.parseInt(SessionProvider.getSessionMapValue("IDPAGELOADTOUR")) + "&page=" + SessionProvider.getSessionMapValue("PAGELOADTOUR").toString());
//            } else if (papeload.equals("debt.jsp")) {
//                sendRedirect("debt.jsp");
//            } else {
                sendRedirect("customer4tour.jsp");
//            }

        } else {
            showGlobalReport(true, getResourceString("datasuccessfail"));
//            if (SessionProvider.getSessionMapValue("PAGELOADTOUR") != null && SessionProvider.getSessionMapValue("IDPAGELOADTOUR") != null) {
//
//                System.out.println("--------VAO DAY KO-----------");
//                sendRedirect("debt.jsp?fb050=" + Util.parseInt(SessionProvider.getSessionMapValue("IDPAGELOADTOUR")) + "&page=" + SessionProvider.getSessionMapValue("PAGELOADTOUR").toString());
//            } else if (papeload.equals("debt.jsp")) {
//                sendRedirect("debt.jsp");
//            } else {
                sendRedirect("customer4tour.jsp");
//            }
        }


    }

    public void approve() {
        int roweffect = 0;

        roweffect = t950Store.approveT950(pt950, getLogin().getUserName());
        if (roweffect >= 0) {
            setFlag(2);
//            System.out.println("55555555555555%%%%%%%%%%%" + flag);
            showGlobalReport(true, getResourceString("datasavesuccessful"));
//            if (SessionProvider.getSessionMapValue("PAGELOADTOUR") != null && SessionProvider.getSessionMapValue("IDPAGELOADTOUR") != null) {
//
//                System.out.println("--------VAO DAY KO-----------");
//                sendRedirect("debt.jsp?fb050=" + Util.parseInt(SessionProvider.getSessionMapValue("IDPAGELOADTOUR")) + "&page=" + SessionProvider.getSessionMapValue("PAGELOADTOUR").toString());
//            } else if (papeload.equals("debt.jsp")) {
//                sendRedirect("debt.jsp");
//            } else {
               sendRedirect("customer4tour.jsp");
//            }
        } else {
            showGlobalReport(true, getResourceString("datasuccessfail"));
//            if (SessionProvider.getSessionMapValue("PAGELOADTOUR") != null && SessionProvider.getSessionMapValue("IDPAGELOADTOUR") != null) {
//
//                System.out.println("--------VAO DAY KO-----------");
//                sendRedirect("debt.jsp?fb050=" + Util.parseInt(SessionProvider.getSessionMapValue("IDPAGELOADTOUR")) + "&page=" + SessionProvider.getSessionMapValue("PAGELOADTOUR").toString());
//            } else if (papeload.equals("debt.jsp")) {
//                sendRedirect("debt.jsp");
//            } else {
               sendRedirect("customer4tour.jsp");
         //   }
        }


    }

    public List<M650> getListdocumentM650() {
        M650Store store = new M650Store();
        try {

            List<M650> listM650 = store.findM650(getLogin().getModule(), getLogin().getCompanyNo(), 0, null, 0, 0, 0, null, "T950", 0, 0, null, null, 0, 10000, 0, 0, getLogin().getUserName());
            System.out.println("--------------------------" + listM650.size());
            return listM650;
        } catch (Exception e) {
            return null;
        }
    }

    // ham chiet khau gaim gia
    public void updateSaleT950() {
        try {
            System.out.println(dbmoney + "----------%------" + flagradio);
            int count = 0;
            if (flagradio == 1) {
                count = t950Store.stdt_tools_updatetabt950dis(pt950, 0, dbmoney, fn100, getLogin().getCompanyNo(), getLogin().getModule(), getLogin().getUserName());
                System.out.println(count + "--------GIAM GIA---" + pt950 + "," + dbmoney + "," + dbmoney + "," + fn100 + "," + getLogin().getCompanyNo() + "," + getLogin().getModule() + "," + getLogin().getUserName());
            } else {
                count = t950Store.stdt_tools_updatetabt950dis(pt950, dbmoney, 0, fn100, getLogin().getCompanyNo(), getLogin().getModule(), getLogin().getUserName());
                System.out.println(count + "--------GIAM GIA---" + pt950 + "," + dbmoney + "," + dbmoney + "," + fn100 + "," + getLogin().getCompanyNo() + "," + getLogin().getModule() + "," + getLogin().getUserName());
            }
            if (count != 0) {
                showGlobalReport(true, getResourceString("datasavesuccessful"));
                sendRedirect("customer4tour.jsp");
            } else {
                sendRedirect("customer4tour.jsp");
            }

        } catch (Exception e) {
        }
    }

    /**
     * @return the pt950
     */
    public int getPt950() {
        return pt950;
    }

    /**
     * @param pt950 the pt950 to set
     */
    public void setPt950(int pt950) {
        this.pt950 = pt950;
    }

    /**
     * @return the fh075
     */
    public int getFh075() {
        return fh075;
    }

    /**
     * @param fh075 the fh075 to set
     */
    public void setFh075(int fh075) {
        this.fh075 = fh075;
    }

    /**
     * @return the hv076
     */
    public String getHv076() {
        return hv076;
    }

    /**
     * @param hv076 the hv076 to set
     */
    public void setHv076(String hv076) {
        this.hv076 = hv076;
    }

    /**
     * @return the ft000
     */
    public int getFt000() {
        return ft000;
    }

    /**
     * @param ft000 the ft000 to set
     */
    public void setFt000(int ft000) {
        this.ft000 = ft000;
    }

    /**
     * @return the tn951
     */
    public int getTn951() {
        return tn951;
    }

    /**
     * @param tn951 the tn951 to set
     */
    public void setTn951(int tn951) {
        this.tn951 = tn951;
    }

    /**
     * @return the tv952
     */
    public String getTv952() {
        return tv952;
    }

    /**
     * @param tv952 the tv952 to set
     */
    public void setTv952(String tv952) {
        this.tv952 = tv952;
    }

    /**
     * @return the td953
     */
    public Date getTd953() {
        if (td953 != null) {
        } else {
            Date date = new Date();
            td953 = date;
        }
        return td953;
    }

    /**
     * @param td953 the td953 to set
     */
    public void setTd953(Date td953) {
        this.td953 = td953;
    }

    /**
     * @return the td954
     */
    public Date getTd954() {
        if (td954 != null) {
        } else {
            Date date = new Date();
            td954 = date;
        }
        return td954;
    }

    /**
     * @param td954 the td954 to set
     */
    public void setTd954(Date td954) {
        this.td954 = td954;
    }

    /**
     * @return the tv955
     */
    public String getTv955() {
        return tv955;
    }

    /**
     * @param tv955 the tv955 to set
     */
    public void setTv955(String tv955) {
        this.tv955 = tv955;
    }

    /**
     * @return the tv956
     */
    public String getTv956() {
        return tv956;
    }

    /**
     * @param tv956 the tv956 to set
     */
    public void setTv956(String tv956) {
        this.tv956 = tv956;
    }

    /**
     * @return the tv97
     */
    public String getTv957() {
        return tv957;
    }

    /**
     * @param tv97 the tv97 to set
     */
    public void setTv957(String tv957) {
        this.tv957 = tv957;
    }

    /**
     * @return the tv958
     */
    public String getTv958() {
        return tv958;
    }

    /**
     * @param tv958 the tv958 to set
     */
    public void setTv958(String tv958) {
        this.tv958 = tv958;
    }

    /**
     * @return the tn959
     */
    public int getTn959() {
        return tn959;
    }

    /**
     * @param tn959 the tn959 to set
     */
    public void setTn959(int tn959) {
        this.tn959 = tn959;
    }

    /**
     * @return the tv960
     */
    public String getTv960() {
        return tv960;
    }

    /**
     * @param tv960 the tv960 to set
     */
    public void setTv960(String tv960) {
        this.tv960 = tv960;
    }

    /**
     * @return the tv961
     */
    public String getTv961() {
        return tv961;
    }

    /**
     * @param tv961 the tv961 to set
     */
    public void setTv961(String tv961) {
        this.tv961 = tv961;
    }

    /**
     * @return the tv962
     */
    public String getTv962() {
        return tv962;
    }

    /**
     * @param tv962 the tv962 to set
     */
    public void setTv962(String tv962) {
        this.tv962 = tv962;
    }

    /**
     * @return the tv963
     */
    public String getTv963() {
        return tv963;
    }

    /**
     * @param tv963 the tv963 to set
     */
    public void setTv963(String tv963) {
        this.tv963 = tv963;
    }

    /**
     * @return the td964
     */
    public Date getTd964() {
        return td964;
    }

    /**
     * @param td964 the td964 to set
     */
    public void setTd964(Date td964) {
        this.td964 = td964;
    }

    /**
     * @return the tv965
     */
    public String getTv965() {
        return tv965;
    }

    /**
     * @param tv965 the tv965 to set
     */
    public void setTv965(String tv965) {
        this.tv965 = tv965;
    }

    /**
     * @return the td966
     */
    public Date getTd966() {
        return td966;
    }

    /**
     * @param td966 the td966 to set
     */
    public void setTd966(Date td966) {
        this.td966 = td966;
    }

    /**
     * @return the tv967
     */
    public String getTv967() {
        return tv967;
    }

    /**
     * @param tv967 the tv967 to set
     */
    public void setTv967(String tv967) {
        this.tv967 = tv967;
    }

    /**
     * @return the tv968
     */
    public String getTv968() {
        return tv968;
    }

    /**
     * @param tv968 the tv968 to set
     */
    public void setTv968(String tv968) {
        this.tv968 = tv968;
    }

    /**
     * @return the tv969
     */
    public String getTv969() {
        return tv969;
    }

    /**
     * @param tv969 the tv969 to set
     */
    public void setTv969(String tv969) {
        this.tv969 = tv969;
    }

    /**
     * @return the tv970
     */
    public String getTv970() {
        return tv970;
    }

    /**
     * @param tv970 the tv970 to set
     */
    public void setTv970(String tv970) {
        this.tv970 = tv970;
    }

    /**
     * @return the tv971
     */
    public String getTv971() {
        return tv971;
    }

    /**
     * @param tv971 the tv971 to set
     */
    public void setTv971(String tv971) {
        this.tv971 = tv971;
    }

    /**
     * @return the fv500
     */
    public int getFv500() {
        return fv500;
    }

    /**
     * @param fv500 the fv500 to set
     */
    public void setFv500(int fv500) {
        this.fv500 = fv500;
    }

    /**
     * @return the fv650
     */
    public int getFv650() {
        return fv650;
    }

    /**
     * @param fv650 the fv650 to set
     */
    public void setFv650(int fv650) {
        this.fv650 = fv650;
    }

    /**
     * @return the ft900
     */
    public int getFt900() {
        return ft900;
    }

    /**
     * @param ft900 the ft900 to set
     */
    public void setFt900(int ft900) {
        this.ft900 = ft900;
    }

    /**
     * @return the fb050
     */
    public int getFb050() {
        return fb050;
    }

    /**
     * @param fb050 the fb050 to set
     */
    public void setFb050(int fb050) {
        this.fb050 = fb050;
    }

    /**
     * @return the fh000
     */
    public int getFh000() {
        return fh000;
    }

    /**
     * @param fh000 the fh000 to set
     */
    public void setFh000(int fh000) {
        this.fh000 = fh000;
    }

    /**
     * @return the fh200
     */
    public int getFh200() {
        return fh200;
    }

    /**
     * @param fh200 the fh200 to set
     */
    public void setFh200(int fh200) {
        this.fh200 = fh200;
    }

    /**
     * @return the t950Inf
     */
    public FinancialInf getT950Inf() {
        return t950Inf;
    }

    /**
     * @param t950Inf the t950Inf to set
     */
    public void setT950Inf(FinancialInf t950Inf) {
        this.t950Inf = t950Inf;
    }

    /**
     * @return the td953st
     */
    public String getTd953st() {
        return td953st;
    }

    /**
     * @param td953st the td953st to set
     */
    public void setTd953st(String td953st) {
        this.td953st = td953st;
    }

    /**
     * @return the td954st
     */
    public String getTd954st() {
        return td954st;
    }

    /**
     * @param td954st the td954st to set
     */
    public void setTd954st(String td954st) {
        this.td954st = td954st;
    }

    /**
     * @return the table
     */
    public String getTable() {
        return table;
    }

    /**
     * @param table the table to set
     */
    public void setTable(String table) {
        this.table = table;
    }

    /**
     * @return the flag
     */
    public int getFlag() {
        return flag;
    }

    /**
     * @param flag the flag to set
     */
    public void setFlag(int flag) {
        this.flag = flag;
    }

    /**
     * @return the mycolor
     */
    public String getMycolor() {
        return mycolor;
    }

    /**
     * @param mycolor the mycolor to set
     */
    public void setMycolor(String mycolor) {
        this.mycolor = mycolor;
    }

    /**
     * @return the pv050
     */
    public int getPv050() {
        return pv050;
    }

    /**
     * @param pv050 the pv050 to set
     */
    public void setPv050(int pv050) {
        this.pv050 = pv050;
    }

    /**
     * @return the tn951St
     */
    public String getTn951St() {
        return tn951St;
    }

    /**
     * @param tn951St the tn951St to set
     */
    public void setTn951St(String tn951St) {
        this.tn951St = tn951St;
    }

    /**
     * @return the ft950
     */
    public int getFt950() {
        return ft950;
    }

    /**
     * @param ft950 the ft950 to set
     */
    public void setFt950(int ft950) {
        this.ft950 = ft950;
    }

    /**
     * @return the pn100t
     */
    public int getPn100t() {
        return pn100t;
    }

    /**
     * @param pn100t the pn100t to set
     */
    public void setPn100t(int pn100t) {
        this.pn100t = pn100t;
    }

    /**
     * @return the pt075
     */
    public int getPt075() {
        return pt075;
    }

    /**
     * @param pt075 the pt075 to set
     */
    public void setPt075(int pt075) {
        this.pt075 = pt075;
    }

    /**
     * @return the papeload
     */
    public String getPapeload() {
        return papeload;
    }

    /**
     * @param papeload the papeload to set
     */
    public void setPapeload(String papeload) {
        this.papeload = papeload;
    }

    /**
     * @return the different
     */
    public int getDifferent() {
        return different;
    }

    /**
     * @param different the different to set
     */
    public void setDifferent(int different) {
        this.different = different;
    }

    /**
     * @return the listCN
     */
    public List<SelectItem> getListCN() {
        listCN = comboboxUtil.getListCombT100CN();
        return listCN;
    }

    /**
     * @param listCN the listCN to set
     */
    public void setListCN(List<SelectItem> listCN) {
        this.listCN = listCN;
    }

    /**
     * @return the tip
     */
    public int getTip() {
        return tip;
    }

    /**
     * @param tip the tip to set
     */
    public void setTip(int tip) {
        this.tip = tip;
    }

    /**
     * @return the FT950CN
     */
    public int getFT950CN() {
        return FT950CN;
    }

    /**
     * @param FT950CN the FT950CN to set
     */
    public void setFT950CN(int FT950CN) {
        this.FT950CN = FT950CN;
    }

    /**
     * @return the fn100
     */
    public int getFn100() {
        return fn100;
    }

    /**
     * @param fn100 the fn100 to set
     */
    public void setFn100(int fn100) {
        this.fn100 = fn100;
    }

    /**
     * @param listT950CNL the listT950CNL to set
     */
    public void setListT950CNL(List<T950> listT950CNL) {
        this.listT950CNL = listT950CNL;
    }

    /**
     * @return the keysearch
     */
    public String getKeysearch() {
        return keysearch;
    }

    /**
     * @param keysearch the keysearch to set
     */
    public void setKeysearch(String keysearch) {
        this.keysearch = keysearch;
    }

    /**
     * @return the typesearch
     */
    public int getTypesearch() {
        return typesearch;
    }

    /**
     * @param typesearch the typesearch to set
     */
    public void setTypesearch(int typesearch) {
        this.typesearch = typesearch;
    }

    /**
     * @return the idtype
     */
    public int getIdtype() {
        return idtype;
    }

    /**
     * @param idtype the idtype to set
     */
    public void setIdtype(int idtype) {
        this.idtype = idtype;
    }

    /**
     * @return the listT950forTour
     */
    public List<T950> getListT950forTour() {
        try {
            V030controller v030Controller = new V030controller();
            System.out.println("--------------THÁM O TOUR CONG NO------" + getLogin().getModule() + "," + getLogin().getCompanyNo() + "," + 0 + "," + ft000 + "," + 0 + "," + v030Controller.getFV050() + "," + pt950 + 0 + "," + "," + 0 + "," + 300 + "," + 0 + "," + 0 + "," + getLogin().getUserName());
            listT950forTour = t950Store.listT950CNforTournew(getLogin().getModule(), getLogin().getCompanyNo(), 0, ft000, 0, v030Controller.getFV050(), pt950, 0, 0, 300, 0, 0, getLogin().getUserName());
            double ln203db = Util.convertStringToDouble(String.valueOf(listT950forTour.get(0).getDoanhso()));
            doanhsoStr = Util.numberformater(ln203db, "##,###,###");
            double ln203db1 = Util.convertStringToDouble(String.valueOf(listT950forTour.get(0).getThu()));
            thuStr = Util.numberformater(ln203db1, "##,###,###");
            double ln203db2 = Util.convertStringToDouble(String.valueOf(listT950forTour.get(0).getTongno()));
            tongnoStr = Util.numberformater(ln203db2, "##,###,###");
            double ln203db23 = Util.convertStringToDouble(String.valueOf(listT950forTour.get(0).getTongchi()));
            tongchiStr = Util.numberformater(ln203db23, "##,###,###");
            System.out.println(doanhsoStr + thuStr + tongnoStr + "--------------CONGNO----TOUR-----" + listT950forTour.size() + "----" + listT950forTour.get(0).getTongchi() + tongchiStr);
        } catch (Exception e) {
        }
        return listT950forTour;
    }

    /**
     * @param listT950forTour the listT950forTour to set
     */
    public void setListT950forTour(List<T950> listT950forTour) {
        this.listT950forTour = listT950forTour;
    }

    public void searchpersonalSystem() {
        try {
            System.out.println("---------KEYSEARCH------------" + keysearch);
            setFlagcus(false);
            SessionProvider.setSessionMapValue(SessionName.KEYSEARCHNAME, keysearch);
            //  list = store.searchListCustomerSGT(getLogin().getModule(), 99, getTypesearch(), getKeySearch(), Offset, Limit, 0, 0, userAction);
        } catch (Exception e) {
        }
    }
// change khach hag

    public void onchangepersonalSystem() {
        try {
            System.out.println("--------TYPE----------" + typecus);
            if (typecus == 1) {
                setBlock("block");
                setNone("none");
            } else {
                setBlock("none");
                setNone("block");
            }
            //  list = store.searchListCustomerSGT(getLogin().getModule(), 99, getTypesearch(), getKeySearch(), Offset, Limit, 0, 0, userAction);
        } catch (Exception e) {
        }
    }
    // change nhan vien

    public void onchangepersonalSystemcombo() {
        try {
            System.out.println("--------PN100 NHAN VIEN----------" + pn100t);
            if (pn100t != 0) {
                SessionProvider.setSessionMapValue(SessionName.PN100NEWKEY, pn100t);
                setBlock1("block");
                setNone1("none");
            } else {
                setBlock1("none");
                setNone1("block");
            }



            ContactStore contactStore = new ContactStore();
            List<N950> listNew = contactStore.getListContactpt(pn100t, 0, getLogin().getUserName());
            if (listNew != null) {
                hoten = listNew.get(0).getNv102() + " " + listNew.get(0).getNv127() + " " + listNew.get(0).getNv103();
                adddress = listNew.get(0).getStr1() + " ," + listNew.get(0).getWARD() + ", " + listNew.get(0).getCITY();
                System.out.println("------HOTEN--------" + hoten + "----" + adddress);
            }
            //  list = store.searchListCustomerSGT(getLogin().getModule(), 99, getTypesearch(), getKeySearch(), Offset, Limit, 0, 0, userAction);
        } catch (Exception e) {
        }
    }

    public void onclickpersonalSystem() {
        try {
            System.out.println(flagcus + "------FLAG--------" + fn100);
            if (flagcus == true) {
                setBlock1("block");
                setNone1("none");
            } else {
                setBlock1("none");
                setNone1("block");
            }
            ContactStore contactStore = new ContactStore();
            List<N950> listNew = contactStore.getListContactpt(fn100, 0, getLogin().getUserName());
            if (listNew != null) {
                hoten = listNew.get(0).getNv102() + " " + listNew.get(0).getNv127() + " " + listNew.get(0).getNv103();
                adddress = listNew.get(0).getStr1() + " ," + listNew.get(0).getWARD() + ", " + listNew.get(0).getCITY();
                System.out.println("------HOTEN--------" + hoten + "----" + adddress);
            }
            //  list = store.searchListCustomerSGT(getLogin().getModule(), 99, getTypesearch(), getKeySearch(), Offset, Limit, 0, 0, userAction);
        } catch (Exception e) {
        }
    }

    public void unonclickpersonalSystem() {
        try {
            System.out.println("------FLAG--------");
            if (flagcus == true) {
                setBlock1("block");
                setNone1("none");
            } else {
                setBlock1("none");
                setNone1("block");
            }
            //  list = store.searchListCustomerSGT(getLogin().getModule(), 99, getTypesearch(), getKeySearch(), Offset, Limit, 0, 0, userAction);
        } catch (Exception e) {
        }
    }

    /**
     * @return the listresultpersonal
     */
    public List<N100> getListresultpersonal() {
        try {
            CustomerStore store = new CustomerStore();
            if (SessionProvider.getSessionMapValue(SessionName.KEYSEARCHNAME) != null) {
                listresultpersonal = store.searchListCustomerSGT(getLogin().getModule(), getLogin().getCompanyNo(), 0, SessionProvider.getSessionMapValue(SessionName.KEYSEARCHNAME).toString(), 0, 30, 0, 0, getLogin().getUserName());
                System.out.println(SessionProvider.getSessionMapValue(SessionName.KEYSEARCHNAME).toString() + "----------------LÍT KHI TIM KIEM TAI CHINH------------" + listresultpersonal.size());
            }


        } catch (Exception e) {
        }

        return listresultpersonal;
    }

    /**
     * @param listresultpersonal the listresultpersonal to set
     */
    public void setListresultpersonal(List<N100> listresultpersonal) {
        this.listresultpersonal = listresultpersonal;
    }

    /**
     * @return the typecus
     */
    public int getTypecus() {
        return typecus;
    }

    /**
     * @param typecus the typecus to set
     */
    public void setTypecus(int typecus) {
        this.typecus = typecus;
    }

    /**
     * @return the flagcus
     */
    public Boolean getFlagcus() {
        return flagcus;
    }

    /**
     * @param flagcus the flagcus to set
     */
    public void setFlagcus(Boolean flagcus) {
        this.flagcus = flagcus;
    }

    /**
     * @return the block
     */
    public String getBlock() {
        return block;
    }

    /**
     * @param block the block to set
     */
    public void setBlock(String block) {
        this.block = block;
    }

    /**
     * @return the none
     */
    public String getNone() {
        return none;
    }

    /**
     * @param none the none to set
     */
    public void setNone(String none) {
        this.none = none;
    }

    /**
     * @return the block1
     */
    public String getBlock1() {
        return block1;
    }

    /**
     * @param block1 the block1 to set
     */
    public void setBlock1(String block1) {
        this.block1 = block1;
    }

    /**
     * @return the none1
     */
    public String getNone1() {
        return none1;
    }

    /**
     * @param none1 the none1 to set
     */
    public void setNone1(String none1) {
        this.none1 = none1;
    }

    /**
     * @return the hoten
     */
    public String getHoten() {
        return hoten;
    }

    /**
     * @param hoten the hoten to set
     */
    public void setHoten(String hoten) {
        this.hoten = hoten;
    }

    /**
     * @return the adddress
     */
    public String getAdddress() {
        return adddress;
    }

    /**
     * @param adddress the adddress to set
     */
    public void setAdddress(String adddress) {
        this.adddress = adddress;
    }

    public void printWord() throws SQLException, SQLException, InstantiationException, ParseException {
        String s = getRequest().getRequestURL().toString();
        String[] arr = new String[20];
        arr = s.split("/");
        String url = "";
        if (arr.length > 3) {
            url = arr[0] + "/" + arr[1] + "/" + arr[2] + "/";
        }
        String hoten = null;
        V030controller v030controller = new V030controller();
        System.out.println("---------------HAM PRINT WORD-----------------" + getLogin().getModule() + "," + getLogin().getCompanyNo() + "," + 0 + "," + ft000 + "," + 0 + "," + v030controller.getFV050() + "," + SessionProvider.getSessionMapValue(SessionName.PT950NEWKEY) + "," + 0 + "," + 0 + "," + 300 + "," + 0 + "," + 0 + "," + getLogin().getUserName());
        listT950 = t950Store.listT950CNforTournew(getLogin().getModule(), getLogin().getCompanyNo(), 0, ft000, 0, v030controller.getFV050(), Util.parseInt(SessionProvider.getSessionMapValue(SessionName.PT950NEWKEY)), 0, 0, 300, 0, 0, getLogin().getUserName());
        //t950Store.listT950(getLogin().getModule(), getLogin().getCompanyNo(), this.getFh075(), this.getFt000(), this.getFb050(), this.getFv500(), this.getFt900(), 0, 100, 0, 1, this.getLogin().getUserName());
        if (listT950 != null && listT950.size() > 0) {
//                for (int i = 0; i < listT950.size(); i++) {
//                    if (listT950.get(i).getPt950() == SessionProvider.getSessionMapValue(SessionName.PT950NEWKEY)) {
            this.pt950 = listT950.get(0).getPt950();
            this.fh075 = listT950.get(0).getFh075();
            this.hv076 = listT950.get(0).getHv076();
            this.ft000 = listT950.get(0).getFt000();
            this.tn951 = listT950.get(0).getTn951();
            if (tn951 != 0) {
                double tn951db = Util.convertStringToDouble(String.valueOf(tn951));
                tn951St = Util.numberformater(tn951db, "##,###,###");
            }
            this.pt075 = listT950.get(0).getFt075();
            this.pn100t = listT950.get(0).getFn100t();
            System.out.println("----------ttttttt--DDD--" + pn100t);
            this.tv952 = listT950.get(0).getTv952();
            this.td953 = listT950.get(0).getTd953();
            System.out.println("---------Ngay thang--" + td953);
            if (td953 != null) {
                dd = td953.toString().substring(8, 10);
                mm = td953.toString().substring(5, 7);
                yy = td953.toString().substring(0, 4);
            }
            System.out.println("---------Ngay thang--" + dd + mm + yy);
            this.td954 = listT950.get(0).getTd954();
            this.tv955 = listT950.get(0).getTv955();
            this.tv956 = listT950.get(0).getTv956();
            this.tv957 = listT950.get(0).getTv957();
            this.tv958 = listT950.get(0).getTv958();
            this.tn959 = listT950.get(0).getTn959();
            this.tv960 = listT950.get(0).getTv960();
            this.tv961 = listT950.get(0).getTv961();
            this.tv962 = listT950.get(0).getTv962();
            this.tv963 = listT950.get(0).getTv963();
           // this.td964 = listT950.get(0).getTd964();
            this.tv965 = listT950.get(0).getTv965();
          //  this.td966 = listT950.get(0).getTd966();
            this.tv967 = listT950.get(0).getTv967();
            this.tv968 = listT950.get(0).getTv968();
            this.tv969 = listT950.get(0).getTv969();
            this.tv970 = listT950.get(0).getTv970();
            this.tv971 = listT950.get(0).getTv971();
            this.pv050 = listT950.get(0).getFb050();
            tv076 = listT950.get(0).getTv076();
            this.fv500 = listT950.get(0).getFb050();
            System.out.println("----- " + tv971);
            this.fv500 = listT950.get(0).getFv500();
            this.fv650 = listT950.get(0).getFv650();
            this.ft900 = listT950.get(0).getFt900();
            this.fb050 = listT950.get(0).getFb050();
            adddress = listT950.get(0).getNv112();
            this.td953st = listT950.get(0).getTd953st().toString();
            hoten = listT950.get(0).getHoten();
            this.td954st = listT950.get(0).getTd954st().toString();
//                    }
//                }
        }

        XWPFDocument document = new XWPFDocument();

        XWPFParagraph paragraphOne = document.createParagraph();
        XWPFParagraph paragraphcenter = document.createParagraph();
        XWPFParagraph paragraphright = document.createParagraph();
        paragraphOne.setAlignment(ParagraphAlignment.LEFT);
        paragraphcenter.setAlignment(ParagraphAlignment.CENTER);
        paragraphright.setAlignment(ParagraphAlignment.RIGHT);
//        paragraphOne.setBorderBottom(Borders.SINGLE);
//        paragraphOne.setBorderTop(Borders.SINGLE);
//        paragraphOne.setBorderRight(Borders.SINGLE);
//        paragraphOne.setBorderLeft(Borders.SINGLE);
//        paragraphOne.setBorderBetween(Borders.SINGLE);

        XWPFRun paragraphOneRunOne = paragraphOne.createRun();
        paragraphOneRunOne.setText("CTY TNHH DU HÀNH SÀI GÒN                                            ");
//        XWPFParagraph paragraphcenter12 = document.createParagraph();
//        paragraphcenter12.setAlignment(ParagraphAlignment.RIGHT);
        paragraphOneRunOne.setFontSize(8);
        paragraphOneRunOne.setText("                                                                                                                                                                                    Mẫu số:02TT");
        paragraphOneRunOne.addBreak();


//        XWPFParagraph paragraphbanhanh = document.createParagraph();
//         paragraphbanhanh.setAlignment(ParagraphAlignment.RIGHT);
        XWPFParagraph paragraphOne133 = document.createParagraph();
        paragraphOne133.setAlignment(ParagraphAlignment.RIGHT);
        XWPFRun paragraphOneRunhanh = paragraphOne.createRun();
        paragraphOneRunhanh.setFontSize(8);
        paragraphOneRunhanh.setText("                                                                                                                                                                  Ban hành theo QĐ số 15/2006QĐBTC");
        paragraphOneRunhanh.addBreak();


        XWPFRun paragraphOneRunTwo = paragraphcenter.createRun();
        paragraphOneRunTwo.setFontSize(14);
        paragraphOneRunTwo.setBold(true);
        paragraphOneRunTwo.setText("PHIẾU CHI   ");
        paragraphOneRunTwo.setFontSize(12);
        paragraphOneRunTwo.setBold(false);
        paragraphOneRunTwo.setText("Số :   ");
        paragraphOneRunTwo.addBreak();


        XWPFRun paragraphOneRunThree = paragraphcenter.createRun();
        paragraphOneRunThree.setText("Ngày  " + dd + "  tháng  " + mm + "  năm " + yy + "");
        paragraphOneRunThree.addBreak();
        XWPFParagraph paragraphOne1 = document.createParagraph();
        paragraphOne1.setAlignment(ParagraphAlignment.LEFT);
        XWPFRun paragraphOneRunOne1 = paragraphOne1.createRun();
        paragraphOneRunOne1.setSubscript(VerticalAlign.BASELINE);
        paragraphOneRunOne1.setText("Họ tên người nhận tiền:" + hoten);
        paragraphOneRunOne1.addBreak();
        XWPFParagraph paragraphOne2 = document.createParagraph();
        paragraphOne2.setAlignment(ParagraphAlignment.LEFT);
        XWPFRun paragraphOneRunOne2 = paragraphOne2.createRun();
        paragraphOneRunOne2.setText("Địa chỉ: " + adddress);
        paragraphOneRunOne2.addBreak();
        XWPFParagraph paragraphOne3 = document.createParagraph();
        paragraphOne3.setAlignment(ParagraphAlignment.LEFT);
        XWPFRun paragraphOneRunOne3 = paragraphOne3.createRun();
        paragraphOneRunOne3.setText("Lý do chi:" + tv076);
        paragraphOneRunOne3.addBreak();
        XWPFParagraph paragraphOne4 = document.createParagraph();
        paragraphOne4.setAlignment(ParagraphAlignment.LEFT);
        XWPFRun paragraphOneRunOne4 = paragraphOne4.createRun();
        paragraphOneRunOne4.setText("Số tiền:                           " + tn951St + "          đồng");
        paragraphOneRunOne4.addBreak();
        XWPFParagraph paragraphOne5 = document.createParagraph();
        paragraphOne5.setAlignment(ParagraphAlignment.LEFT);
        XWPFRun paragraphOneRunOne5 = paragraphOne5.createRun();
        paragraphOneRunOne5.setText("Bằng chữ:");
        paragraphOneRunOne5.addBreak();
        XWPFParagraph paragraphOne6 = document.createParagraph();
        paragraphOne6.setAlignment(ParagraphAlignment.LEFT);
        XWPFRun paragraphOneRunOne6 = paragraphOne6.createRun();
        paragraphOneRunOne6.setText("Kèm theo:                                chứng từ gốc : ");
        paragraphOneRunOne6.addBreak();
        XWPFParagraph paragraphOne7 = document.createParagraph();
        paragraphOne7.setAlignment(ParagraphAlignment.RIGHT);
        XWPFRun paragraphOneRunOne7 = paragraphOne7.createRun();
        paragraphOneRunOne7.setText("Ngày  " + dd + "  tháng  " + mm + "  năm " + yy + "");
        paragraphOneRunOne7.addBreak();
        XWPFParagraph paragraphOne8 = document.createParagraph();
        paragraphOne8.setAlignment(ParagraphAlignment.CENTER);
        XWPFRun paragraphOneRunOne8 = paragraphOne8.createRun();
        paragraphOneRunOne8.setText("Người lập phiếu     Người nhận tiền    Thủ quỹ    KT Trưởng    Giám đốc");
        paragraphOneRunOne8.addBreak();

        try {
            File fileout = new File(ResourcesProvider.getReportExcel() + "phieuthu.docx");
            // File fileout = new File("D:\\" + hotenD + ".docx");
            FileOutputStream out = new FileOutputStream(fileout);


            document.write(out);
            out.close();
            // sendRedirect(url + "resources/excel/"+hotenD+".docx");
            System.out.println("sendRedirect----:" + url + "resources/excel/phieuthu.docx");
            SessionProvider.setSessionMapValue("LINKSAVE", url + "resources/excel/phieuthu.docx");
            sendRedirect("viewdocument.jsp");
        } catch (Exception e) {
        }

    }

    /**
     * @return the tv076
     */
    public String getTv076() {
        return tv076;
    }

    /**
     * @param tv076 the tv076 to set
     */
    public void setTv076(String tv076) {
        this.tv076 = tv076;
    }

    /**
     * @return the dd
     */
    public String getDd() {
        return dd;
    }

    /**
     * @param dd the dd to set
     */
    public void setDd(String dd) {
        this.dd = dd;
    }

    /**
     * @return the mm
     */
    public String getMm() {
        return mm;
    }

    /**
     * @param mm the mm to set
     */
    public void setMm(String mm) {
        this.mm = mm;
    }

    /**
     * @return the yy
     */
    public String getYy() {
        return yy;
    }

    /**
     * @param yy the yy to set
     */
    public void setYy(String yy) {
        this.yy = yy;
    }

    /**
     * @return the flagradio
     */
    public int getFlagradio() {
        return flagradio;
    }

    /**
     * @param flagradio the flagradio to set
     */
    public void setFlagradio(int flagradio) {
        this.flagradio = flagradio;
    }

    /**
     * @return the dbmoney
     */
    public double getDbmoney() {
        return dbmoney;
    }

    /**
     * @param dbmoney the dbmoney to set
     */
    public void setDbmoney(double dbmoney) {
        this.dbmoney = dbmoney;
    }

    /**
     * @return the listT950CNchild
     */
    public List<T950> getListT950CNchild() {
        try {
            System.out.println("--------LIST CHILD------" + getLogin().getModule() + "," + getLogin().getCompanyNo() + "," + pt950 + "," + getLogin().getUserName());
            listT950CNchild = t950Store.tcurpks_listoftabt950child(getLogin().getModule(), getLogin().getCompanyNo(), pt950, getLogin().getUserName());
        } catch (Exception e) {
        }
        return listT950CNchild;
    }

    /**
     * @param listT950CNchild the listT950CNchild to set
     */
    public void setListT950CNchild(List<T950> listT950CNchild) {
        this.listT950CNchild = listT950CNchild;
    }

    /**
     * @return the doanhsoStr
     */
    public String getDoanhsoStr() {
        return doanhsoStr;
    }

    /**
     * @param doanhsoStr the doanhsoStr to set
     */
    public void setDoanhsoStr(String doanhsoStr) {
        this.doanhsoStr = doanhsoStr;
    }

    /**
     * @return the thuStr
     */
    public String getThuStr() {
        return thuStr;
    }

    /**
     * @param thuStr the thuStr to set
     */
    public void setThuStr(String thuStr) {
        this.thuStr = thuStr;
    }

    /**
     * @return the tongnoStr
     */
    public String getTongnoStr() {
        return tongnoStr;
    }

    /**
     * @param tongnoStr the tongnoStr to set
     */
    public void setTongnoStr(String tongnoStr) {
        this.tongnoStr = tongnoStr;
    }

    public void onchangeusd() {
        try {
            System.out.println("------------ONCHANGE--------USD---" + tv952);
        } catch (Exception e) {
        }
    }

    /**
     * @return the tongchiStr
     */
    public String getTongchiStr() {
        return tongchiStr;
    }

    /**
     * @param tongchiStr the tongchiStr to set
     */
    public void setTongchiStr(String tongchiStr) {
        this.tongchiStr = tongchiStr;
    }
    
  private Sheet createHeader(Sheet sheet, int row, HSSFCellStyle style) {
        List<SelectItem> header = new ArrayList<SelectItem>();
        header.add(new SelectItem(3000, "STT"));
        header.add(new SelectItem(5000, "Họ và tên"));
        header.add(new SelectItem(2000, "Giới tính"));
        header.add(new SelectItem(2000, "Ngày sinh"));
        header.add(new SelectItem(3000, "CMND"));
        header.add(new SelectItem(2000, "Ngày cấp"));
        header.add(new SelectItem(2000, "Ngày vào làm"));
        header.add(new SelectItem(2000, "Điện thoại"));
        header.add(new SelectItem(2000, "Địa chỉ"));
        header.add(new SelectItem(2000, "Tài khoản"));
        header.add(new SelectItem(3000, "Ngân Hàng"));
        Row row_header = sheet.createRow(row);
        for (int i = 0; i < header.size(); i++) {
            Cell c = row_header.createCell(i);
            c.setCellValue(header.get(i).getLabel());
            c.setCellStyle(style);
            sheet.setColumnWidth(i, Integer.parseInt(header.get(i).getValue().toString()));
        }
        return sheet;
    }

    public void exportExcel() {
        //String path = "E:\\qapi\\build\\web\\resources\\excel" + "\\report.xls";
        String s = getRequest().getRequestURL().toString();
        String[] arr = new String[20];
        arr = s.split("/");
        String url = "";
        if (arr.length > 3) {
            url = arr[0] + "/" + arr[1] + "/" + arr[2] + "/";
        }
        try {
            HSSFCellStyle styleTitle = (HSSFCellStyle) wb.createCellStyle();
            styleTitle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
            styleTitle.setAlignment(CellStyle.ALIGN_CENTER);
            styleTitle.setWrapText(true);
            HSSFFont font = (HSSFFont) wb.createFont();
           // font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
            font.setFontHeightInPoints((short) 10);
            font.setFontName("Arial");

            styleTitle.setFont(font);

            HSSFCellStyle styleHeader = (HSSFCellStyle) wb.createCellStyle();
            styleHeader.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
            styleHeader.setAlignment(CellStyle.ALIGN_CENTER);
            styleHeader.setWrapText(true);
            styleHeader.setFillForegroundColor(HSSFColor.ROYAL_BLUE.index);
            styleHeader.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
            styleHeader.setBorderBottom(HSSFCellStyle.BORDER_THIN);
            styleHeader.setBorderLeft(HSSFCellStyle.BORDER_THIN);
            styleHeader.setBorderRight(HSSFCellStyle.BORDER_THIN);
            styleHeader.setBorderTop(HSSFCellStyle.BORDER_THIN);

            HSSFFont font2 = (HSSFFont) wb.createFont();
            font2.setFontName("Arial");
            font2.setFontHeightInPoints((short) 10);
            font2.setFontHeightInPoints((short) 10);
            styleHeader.setFont(font2);


            HSSFCellStyle styleLeft = (HSSFCellStyle) wb.createCellStyle();
            styleLeft.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
            styleLeft.setAlignment(CellStyle.ALIGN_LEFT);
            styleLeft.setBorderBottom(HSSFCellStyle.BORDER_THIN);
            styleLeft.setBorderLeft(HSSFCellStyle.BORDER_THIN);
            styleLeft.setBorderRight(HSSFCellStyle.BORDER_THIN);
            styleLeft.setWrapText(true);

            HSSFCellStyle styleCenter = (HSSFCellStyle) wb.createCellStyle();
            styleCenter.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
            styleCenter.setAlignment(CellStyle.ALIGN_CENTER);
            styleCenter.setBorderBottom(HSSFCellStyle.BORDER_THIN);
            styleCenter.setBorderLeft(HSSFCellStyle.BORDER_THIN);
            styleCenter.setBorderRight(HSSFCellStyle.BORDER_THIN);
            styleCenter.setWrapText(true);

            HSSFCellStyle styleRight = (HSSFCellStyle) wb.createCellStyle();
            styleRight.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
            styleRight.setAlignment(CellStyle.ALIGN_RIGHT);
            styleRight.setBorderBottom(HSSFCellStyle.BORDER_THIN);
            styleRight.setBorderLeft(HSSFCellStyle.BORDER_THIN);
            styleRight.setBorderRight(HSSFCellStyle.BORDER_THIN);
            styleRight.setWrapText(true);
//            HSSFFont font3 = (HSSFFont) wb.createFont();
//            font3.setFontName("Arial");
//            font3.setFontHeightInPoints((short) 10);
//
//            styleHeader.setFont(font3);


            Sheet sheet = wb.createSheet("PHIEU THU");

            Row rowTitle = sheet.createRow(0);
            //new Region(currentRow,(short)0,currentRow,(short)10
            sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 5));
            Cell cellTitle = rowTitle.createCell(0);
            cellTitle.setCellValue("CÔNG TY TNHH DU HÀNH SÀI GÒN");
            cellTitle.setCellStyle(styleTitle);
            sheet.addMergedRegion(new CellRangeAddress(0, 0, 9, 11));
             Cell cellTitle1 = rowTitle.createCell(9);
            cellTitle1.setCellValue("NGUYEN TUNG");
            cellTitle1.setCellStyle(styleTitle);
         //   currentRow = currentRow + 2;
          //  sheet = createHeader(sheet, 5, styleHeader);
          //  currentRow++;
         //   sheet = createContent(sheet, 5, styleLeft, styleCenter, styleRight);




            String tempStr = ResourcesProvider.getReportExcel();
            if (!(new File(tempStr)).exists()) {
                (new File(tempStr)).mkdirs();
            }
            //setup print
            PrintSetup ps = sheet.getPrintSetup();
            sheet.setAutobreaks(true);
            sheet.setMargin(Sheet.LeftMargin, 0.5);
            sheet.setMargin(Sheet.RightMargin, 0.5);

            ps.setLandscape(true);
            ps.setPaperSize(HSSFPrintSetup.A4_PAPERSIZE);
            ps.setFitWidth((short) 0);
            ps.setFitHeight((short) 0);
            //end setup print

            File fileout = new File(ResourcesProvider.getReportExcel() + "report.xls");
            FileOutputStream fileOut = new FileOutputStream(fileout);
            wb.write(fileOut);
            fileOut.close();

           // sendRedirect(url + "resources/excel/report.xls");
             sendRedirect("http://localhost:8084/trunk/resources/excel/report.xls");

            System.out.println("sendRedirect----:" + ResourcesProvider.getReportExcel() + "report.xls");
//            sendRedirect("E://Q_//kapi//build//web//resources//excel//" + "report.xls");

        } catch (Exception e) {
            System.out.println("--------------AAAAA------"+e.getMessage());
        }




    }

    private Sheet createContent(Sheet sheet, int row, HSSFCellStyle left, HSSFCellStyle center, HSSFCellStyle right) {
        try {
            EmployeeStore employeeStore = new EmployeeStore();
          List<N100>  listEmployee = employeeStore.getListN100OutExcel(getLogin().getModule(), getLogin().getCompanyNo(), 0, 0, getLogin().getUserName());
            System.out.println("TUNG----------LIST--N100---------------- " + listEmployee.size());
            for (int i = 0; i < listEmployee.size(); i++) {
                try {


                    N100 v050 = listEmployee.get(i);
                    Row r = sheet.createRow(row);//ma tour
                    Cell c = r.createCell(0);
                    if (v050.getVv051() != null) {
                        c.setCellValue(v050.getVv051());
                    }
                    c.setCellStyle(center);
                    //Họ và tên
                    Cell c1 = r.createCell(1);
                    if (v050.getHoten() != null) {
                        c1.setCellValue(v050.getHoten());
                    }
                    c1.setCellStyle(left);
                    //giới tính
                    Cell c2 = r.createCell(2);
                    c2.setCellValue(v050.getNv107());
                    c2.setCellStyle(center);
                    //Ngày tháng năm sinh
                    Cell c3 = r.createCell(3);
                    //  c3.setCellValue(v050.getNd128());
                    try {
                        c3.setCellValue(sdf.format(Util.toSQLDate(v050.getNd128())));
                    } catch (Exception e) {
                    }
                    c3.setCellStyle(center);
                    //Số CMND	
                    Cell c4 = r.createCell(4);
                    c4.setCellValue(v050.getNv109());
                    c4.setCellStyle(right);
                    //Ngày cấp
                    Cell c5 = r.createCell(5);
                    try {
                        c5.setCellValue(sdf.format(Util.toSQLDate(v050.getNd352())));
                    } catch (Exception e) {
                    }
                    c5.setCellStyle(center);
                    //Ngày vào làm
                    Cell c6 = r.createCell(6);
                    try {
                        c6.setCellValue(sdf.format(Util.toSQLDate(v050.getNd124())));
                    } catch (Exception e) {
                    }
                    //  c6.setCellStyle(center);
                    //Điện thoại		
                    Cell c7 = r.createCell(7);
                    c7.setCellValue(v050.getNv121());
                    c7.setCellStyle(right);

                    //địa chỉ	
                    Cell c8 = r.createCell(8);
                    c8.setCellValue(v050.getNv112());
                    c8.setCellStyle(right);


                    c8.setCellStyle(center);
                    //tài khoản
                    Cell c9 = r.createCell(9);

                    c9.setCellValue(v050.getNv117());

                    c9.setCellStyle(center);
//                    Cell c9 = r.createCell(9);
//                    if (v050.getVn077() > 9 && v050.getVn078() > 9) {
//                        c8.setCellValue(v050.getVn077() + " : " + v050.getVn078());
//                    } else if (v050.getVn077() < 9 && v050.getVn078() > 9) {
//                        c9.setCellValue("0" + v050.getVn077() + " : " + v050.getVn078());
//                    } else if (v050.getVn077() > 9 && v050.getVn078() < 9) {
//                        c9.setCellValue(v050.getVn077() + " : 0" + v050.getVn078());
//                    }
//                    c8.setCellStyle(center);
                    //Ngân hàng
                    Cell c10 = r.createCell(10);

                    c10.setCellValue(v050.getNv118());

                    c10.setCellStyle(center);

//
//                    c12.setCellStyle(left);
//                    //trang thai
//                    Cell c13 = r.createCell(13);
//                    if (v050.getVv066() != null) {
//                        if (v050.getVv066().equals("T")) {
//                            c13.setCellValue("Tour");
//                        } else {
//                           c13.setCellValue("Sale");
//                        }
//                    }

//                    c13.setCellStyle(center);
//                    //mo ta
//                    Cell c14 = r.createCell(14);
//                    SimpleDateFormat sdf1 = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
//                    if (v050.getVl098()!= null && v050.getVl099()!= null) {
//                        try {
//                            c14.setCellValue(sdf1.format(Util.toSQLDate(v050.getVl098())) + v050.getVl099());
//                        } catch (Exception e) {
//                            c14.setCellValue(v050.getVl099());
//                            
//                        }
//                    }
//
//                    c14.setCellStyle(center);
                    row++;
                } catch (Exception e) {
                    System.out.println(i + " -- " + e.getMessage());
                    continue;
                }

            }
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return sheet;
    }


}
